package hk.m4s.lr.repair.test.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.MyOrderModel;
import hk.m4s.lr.repair.test.model.MyWaiteOrderModel;
import hk.m4s.lr.repair.test.ui.goods.PayMoneyActivity;
import hk.m4s.lr.repair.test.ui.user.CancalOrderActivity;
import hk.m4s.lr.repair.test.ui.user.LookUnprocessedOrderActivity;
import hk.m4s.lr.repair.test.ui.user.MyWaiteMoneyActivity;
import hk.m4s.lr.repair.test.views.listview.InnerListView;

/**
 * @author
 */
public class MyWaiteMoneyAdapter extends BaseAdapter {
    private MyWaiteMoneyActivity context;
    public List<MyOrderModel.ListBean> items;
    private List<MyWaiteOrderModel> myjiangLiModelList=new ArrayList<>();
    private ItemWaiteMoneyAdapter adapter;
    int selectNums = 0;

    public MyWaiteMoneyAdapter(MyWaiteMoneyActivity context,
                               List<MyOrderModel.ListBean> items) {
        this.context = context;
        this.items = items;
    }

    public int getCount() {
        return 2;
    }

    public Object getItem(int position) {
        return getView(position, null, null);
    }

    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.list_item_my_waite_money, null);
            holder = new ViewHolder();
            holder.order_shop_time = (TextView) convertView.findViewById(R.id.order_shop_time);
            holder.order_shop_totlaprice= (TextView) convertView.findViewById(R.id.order_shop_totlaprice);
            holder.cancle_order = (Button) convertView.findViewById(R.id.cancle_order);
            holder.pay_btn = (Button) convertView.findViewById(R.id.pay_btn);
            holder.header = (RelativeLayout) convertView.findViewById(R.id.header);
            holder.itemList = (InnerListView) convertView.findViewById(R.id.itemList);
            holder.order_shop_state= (TextView) convertView.findViewById(R.id.order_shop_state);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.cancle_order.setTag(position);
        holder.pay_btn.setTag(position);
        holder.header.setTag(position);

       // MyOrderModel.ListBean model = items.get(position);

        holder.header.setVisibility(View.VISIBLE);
//        holder.order_shop_time.setText("下单时间:" + AppTools.getStrTime(model.getAdd_time()));
//        holder.order_shop_state.setText("等待付款");
        holder.cancle_order.setVisibility(View.VISIBLE);
        holder.cancle_order.setText("取消订单");
        holder.pay_btn.setText("立即支付");
//        holder.order_shop_totlaprice.setText(MoneyTool.getLocalMoney(model.getActual_money()));
//        if (model.getDetail() != null) {
//            myjiangLiModelList = new ArrayList<>();
//            for (MyOrderModel.ListBean.DetailBean detailBean : model.getDetail()) {
//                MyWaiteOrderModel waiteOrderModel = new MyWaiteOrderModel();
//                waiteOrderModel.setTime(AppTools.getStrTime(detailBean.getAddTime()));
//                waiteOrderModel.setGoods_id(detailBean.getGoods_id());
//                waiteOrderModel.setName(detailBean.getGoods_name());
//                waiteOrderModel.setPrice(detailBean.getGoods_price());
//                waiteOrderModel.setSize(detailBean.getGoods_color());
//                waiteOrderModel.setBuyNum(detailBean.getGoods_num());
//                waiteOrderModel.setState(detailBean.getStatus());
//                waiteOrderModel.setImg(detailBean.getImg());
//                myjiangLiModelList.add(waiteOrderModel);
//            }
            adapter = new ItemWaiteMoneyAdapter(context,myjiangLiModelList);
            holder.itemList.setAdapter(adapter);
//        }
        holder.header.setOnClickListener(new View.OnClickListener()

        {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
                //MyOrderModel.ListBean model = items.get(num);
                Intent aboutIntent = new Intent(context, LookUnprocessedOrderActivity.class);
                //aboutIntent.putExtra("orderId", model.getOrder_id());
                aboutIntent.putExtra("statuts","1");
//                if (model.getPayInfo().getOilMoney()!= null) {
//                    aboutIntent.putExtra("oilMoney", model.getPayInfo().getOilMoney());
//                }
                context.startActivity(aboutIntent);
            }
        });
//
        holder.cancle_order.setOnClickListener(new View.OnClickListener()

        {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
               // MyOrderModel.ListBean myOrderModel = items.get(num);
                Intent intent = new Intent(context, CancalOrderActivity.class);
                //intent.putExtra("model", myOrderModel);
                intent.putExtra("type","1");
                context.startActivity(intent);

            }
        });
        holder.pay_btn.setOnClickListener(new View.OnClickListener()

        {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
               // MyOrderModel.ListBean detailBean = items.get(num);
                Intent intent = new Intent(context, PayMoneyActivity.class);
//                 intent.putExtra("totalMoney",detailBean.getPayInfo().getPaymentMoney());
//                intent.putExtra("yunMoney",detailBean.getPayInfo().getFreight());
//                intent.putExtra("actual_money",detailBean.getPayInfo().getGoodsMoney());
//                intent.putExtra("orderId", detailBean.getPayInfo().getOrderNumber());
//                if (detailBean.getPayInfo().getOilMoney()!= null) {
//                    intent.putExtra("show", "2");
//                    intent.putExtra("oilMoney", detailBean.getPayInfo().getOilMoney());
//                } else {
//                   intent.putExtra("show", "1");
//                }
                intent.putExtra("goPay", "2");
                context.startActivity(intent);

            }
        });
        return convertView;
    }

    private class ViewHolder {
        TextView order_shop_time,order_shop_totlaprice,order_shop_state;
        Button cancle_order, pay_btn;
        private RelativeLayout header;
        InnerListView itemList;
    }
}
